<template>
  <div class="cyberpunk-wrapper">
    <div class="cyberpunk-container">
      <div class="cyberpunk-login">
        <div class="cyberpunk-header">
          <h2 class="cyberpunk-title">SYSTEM LOGIN</h2>
          <div class="cyberpunk-line"></div>
        </div>
        <form @submit.prevent="login" class="cyberpunk-form">
          <div class="cyberpunk-input-group">
            <input 
              placeholder="USERNAME" 
              id="phone" 
              v-model="user.phone" 
              type="text" 
              autocomplete="off" 
              required
              class="cyberpunk-input"
            />
            <span class="cyberpunk-highlight"></span>
            <span class="cyberpunk-bar"></span>
          </div>

          <div class="cyberpunk-input-group">
            <input 
              placeholder="PASSWORD" 
              id="password" 
              v-model="user.userPassword" 
              type="password" 
              autocomplete="off" 
              required
              class="cyberpunk-input"
            />
            <span class="cyberpunk-highlight"></span>
            <span class="cyberpunk-bar"></span>
          </div>

          <button type="submit" class="cyberpunk-button">
            <span class="cyberpunk-button-text">登录</span>
            <span class="cyberpunk-button-glitch"></span>
            <span class="cyberpunk-button-detail"></span>
          </button>
        </form>
        <div class="cyberpunk-grid">
          <div class="cyberpunk-grid-line"></div>
          <div class="cyberpunk-grid-line"></div>
          <div class="cyberpunk-grid-line"></div>
        </div>
      </div>
      <div class="cyberpunk-scanline"></div>
    </div>
  </div>
</template>

<script setup>
import {ref} from 'vue'
import request from '@/util/request.js'
import {ElMessage} from 'element-plus'
import router from '@/router/index.js'

const user = ref({
  phone: '',
  userPassword: ''
})

const login = () => {
  request
      .post('/user/login', user.value)
      .then((response) => {
        console.log('登录接口-后台返回的数据：', response)
        // 存储 Token 到本地
        localStorage.setItem('token', response.data.tokenValue) 
        if (response.code === 200) {
          ElMessage.success('登录成功')
          router.push('/home')

        } else {
          ElMessage.error(response.message)
        }
      })
      .catch((error) => {
        console.log('登录失败-错误信息：', error)
      })
}
</script>

<style scoped>
/* 基础重置 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* 主体样式 */
.cyberpunk-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #0a0a0a;
  background-image: 
    linear-gradient(rgba(0, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
  position: relative;
}

.cyberpunk-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  padding: 40px;
  background: rgba(10, 10, 20, 0.8);
  border-radius: 5px;
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.2),
              0 0 40px rgba(0, 255, 255, 0.1);
  border: 1px solid rgba(0, 255, 255, 0.3);
  z-index: 1;
  overflow: hidden;
}

.cyberpunk-login {
  position: relative;
  z-index: 2;
}

/* 标题样式 */
.cyberpunk-header {
  margin-bottom: 40px;
  text-align: center;
}

.cyberpunk-title {
  color: #00ffff;
  font-family: 'Courier New', monospace;
  font-size: 28px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 5px;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.7);
  margin-bottom: 15px;
}

.cyberpunk-line {
  height: 2px;
  background: linear-gradient(90deg, transparent, #00ffff, transparent);
  margin: 0 auto;
  width: 80%;
}

/* 输入框样式 */
.cyberpunk-input-group {
  position: relative;
  margin-bottom: 30px;
}

.cyberpunk-input {
  width: 100%;
  padding: 15px 10px;
  font-size: 16px;
  color: #00ffff;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(0, 255, 255, 0.5);
  outline: none;
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
}

.cyberpunk-input::placeholder {
  color: rgba(0, 255, 255, 0.5);
  font-family: 'Courier New', monospace;
}

.cyberpunk-highlight {
  position: absolute;
  height: 60%;
  width: 100px;
  top: 25%;
  left: 0;
  pointer-events: none;
  opacity: 0.5;
  background: rgba(0, 255, 255, 0.3);
  filter: blur(10px);
}

.cyberpunk-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: #00ffff;
  transition: width 0.3s ease;
}

.cyberpunk-input:focus ~ .cyberpunk-bar {
  width: 100%;
}

/* 按钮样式 */
.cyberpunk-button {
  position: relative;
  display: block;
  width: 100%;
  padding: 15px;
  margin-top: 40px;
  background: transparent;
  border: 1px solid #00ffff;
  color: #00ffff;
  font-family: 'Courier New', monospace;
  font-size: 16px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 2px;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.3s ease;
  z-index: 1;
}

.cyberpunk-button:hover {
  background: rgba(0, 255, 255, 0.1);
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.cyberpunk-button-text {
  position: relative;
  z-index: 2;
}

.cyberpunk-button-glitch {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, 
    transparent 45%, 
    #ff00ff 45%, 
    #ff00ff 55%, 
    transparent 55%);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1;
}

.cyberpunk-button:hover .cyberpunk-button-glitch {
  opacity: 0.3;
}

.cyberpunk-button-detail {
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 10px;
  height: 10px;
  background: #00ffff;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cyberpunk-button:hover .cyberpunk-button-detail {
  opacity: 1;
}

/* 网格背景 */
.cyberpunk-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
}

.cyberpunk-grid-line {
  position: absolute;
  background: rgba(0, 255, 255, 0.05);
}

.cyberpunk-grid-line:nth-child(1) {
  top: 33%;
  left: 0;
  width: 100%;
  height: 1px;
}

.cyberpunk-grid-line:nth-child(2) {
  top: 66%;
  left: 0;
  width: 100%;
  height: 1px;
}

.cyberpunk-grid-line:nth-child(3) {
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
}

/* 扫描线效果 */
.cyberpunk-scanline {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 255, 255, 0.05) 50%,
    transparent 100%
  );
  animation: scan 8s linear infinite;
  z-index: 3;
  pointer-events: none;
}

@keyframes scan {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

/* 响应式调整 */
@media (max-width: 600px) {
  .cyberpunk-container {
    padding: 30px 20px;
    margin: 0 20px;
  }
  
  .cyberpunk-title {
    font-size: 22px;
  }
}
</style>